﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
using Verse.AI;
using MVCF.Utilities;
using HarmonyLib;

namespace Miao.Stand
{
    [Obsolete("会造成非替身小人的损耗，不用")]
    public class JobGiver_AIStandRoot : ThinkNode_JobGiver
    {
        /// <summary>
        /// 获取优先权
        /// </summary>
        /// <param name="pawn"></param>
        /// <returns></returns>
        public override float GetPriority(Pawn pawn)
        {
            return base.GetPriority(pawn);
        }
        protected override Job TryGiveJob(Pawn pawn)
        {
            StandMasterHediff standMasterHediff = pawn.GetStandHediff();

            if (standMasterHediff != null)
            {
                if (!standMasterHediff.stand.Spawned)
                {
                    bool melee = true;
                    foreach (var range in pawn.AllRangedVerbsPawn())
                    {
                        melee = false;
                        if (standMasterHediff.stand.IsMeleeStand)
                        {
                            if (pawn.mindState.meleeThreat != null)
                            {
                                standMasterHediff.ActiveStand(pawn.Position, pawn.Map);
                            }
                        }
                        else
                        {
                            standMasterHediff.ActiveStand(pawn.Position, pawn.Map);
                        }
                        return null;
                    }
                    if (melee)
                    {
                        standMasterHediff.ActiveStand(pawn.Position, pawn.Map);
                    }
                }
            }
            return null;
        }
    }
}
